/*
 * Copyright 2010 Kevin L'Huillier <klhuillier@gmail.com>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package org.lhuillier.pwsafe.model;


import static org.lhuillier.pwsafe.model.PrefStorageType.*;


public enum BooleanPrefType {
    /**
     * Always keep Password Safe on top.
     */
    ALWAYS_ON_TOP(false, APPLICATION),
    /**
     * Show password in Add &amp; Edit.
     */
    SHOW_PW_DEFAULT(false, DATABASE),
    /**
     * Show password in Tree View.
     */
    SHOW_PASSWORD_IN_TREE(false, DATABASE),
    /**
     * Sort the column selected by {@link IntegerPrefType#SORTED_COLUMN}
     * ascending.
     */
    SORT_ASCENDING(true, DATABASE),
    /**
     * Use {@link StringPrefType#DEFAULT_USERNAME} as the default username.
     * <p>
     * Negates {@link #QUERY_SET_DEF}.
     */
    USE_DEFAULT_USER(false, DATABASE),
    /**
     * Save database immediately after Edit or Add.
     */
    SAVE_IMMEDIATELY(true, DATABASE),
    /**
     * Use lowercase letters.
     */
    PW_USE_LOWERCASE(true, DATABASE),
    /**
     * Use UPPERCASE letters.
     */
    PW_USE_UPPERCASE(true, DATABASE),
    /**
     * Use digits.
     */
    PW_USE_DIGITS(true, DATABASE),
    /**
     * Use symbols. (e.g., ., %, $, etc.)
     */
    PW_USE_SYMBOLS(false, DATABASE),
    /**
     * Use hexadecimal digits only. (0-9, a-f)
     */
    PW_USE_HEX_DIGITS(false, DATABASE),
    /**
     * Use only easy-to-read characters. (i.e., no 'l', '1', etc.)
     */
    PW_USE_EASY_VISION(false, DATABASE),
    /**
     * Confirm item copy to clipboard.
     * <p>
     * This appears to be misnamed, as it seems it should be askquestion in
     * the main Password Safe project. Regardless, it's not used by us.
     */
    DONT_ASK_QUESTION(false, APPLICATION),
    /**
     * Confirm deletion of items.
     * @deprecated because undo is now supported
     */
    @Deprecated
    DELETE_QUESTION(false, OBSOLETE),
    /**
     * Double-click to show password.
     */
    DC_SHOWS_PASSWORD(false, APPLICATION),
    /**
     * @deprecated it is now replaced by two new entries.
     */
    @Deprecated
    DONT_ASK_MINIMIZE_CLEAR_YES_NO(true, OBSOLETE),
    DATABASE_CLEAR(false, APPLICATION),
    /**
     * @deprecated no reason given
     */
    @Deprecated
    DONT_ASK_SAVE_MINIMIZE(false, OBSOLETE),
    /**
     * Query user to set default username.
     * <p>
     * Negates {@link #USE_DEFAULT_USER}.
     */
    QUERY_SET_DEF(true, APPLICATION),
    /**
     * Specific to the main Password Safe project.
     */
    USE_NEW_TOOLBAR(true, APPLICATION),
    /**
     * Put icon in System Tray.
     */
    USE_SYSTEM_TRAY(true, APPLICATION),
    /**
     * Lock password database on workstation lock.
     */
    LOCK_ON_WINDOW_LOCK(true, APPLICATION),
    /**
     * @deprecated was application-wide, but is now DB-specific
     */
    @Deprecated
    LOCK_ON_IDLE_TIMEOUT(true, OBSOLETE),
    /**
     * Escape key closes application.
     */
    ESC_EXITS(true, APPLICATION),
    /**
     * @deprecated as of v3, all text is now stored as UTF-8
     */
    @Deprecated
    IS_UTF8(true, DATABASE),
    /**
     * Presumably this enabled the use of hotkeys such as ^enter to open
     * the Edit dialog.
     */
    HOT_KEY_ENABLED(false, APPLICATION),
    /**
     * Recent Databases on File Menu rather than as a sub-menu.
     */
    MRU_ON_FILE_MENU(true, APPLICATION),
    /**
     * @deprecated no reason given
     */
    @Deprecated
    DISPLAY_EXPANDED_ADD_EDIT_DLG(true, OBSOLETE),
    /**
     * Record last access times.
     */
    MAINTAIN_DATE_TIME_STAMPS(false, DATABASE),
    /**
     * Save {@link IntegerPrefType#NUM_PW_HISTORY_DEFAULT} previous passwords.
     * per entry by default. This can be overridden per entry with
     * that entry's {@link PasswordHistory}.
     */
    SAVE_PASSWORD_HISTORY(false, DATABASE),
    /**
     * @deprecated no reason given
     */
    @Deprecated
    FIND_WRAPS(false, OBSOLETE),
    /**
     * Show Notes in Edit.
     */
    SHOW_NOTES_DEFAULT(false, DATABASE),
    /**
     * Create intermediate backups before saving.
     */
    BACKUP_BEFORE_EVERY_SAVE(true, APPLICATION),
    /**
     * Warn {@link IntegerPrefType#PRE_EXPIRY_WARN_DAYS} days before passwords
     * expire.
     */
    PRE_EXPIRY_WARN(false, APPLICATION),
    /**
     * Put Groups first in Tree View.
     */
    EXPLORER_TREE_TYPE(false, APPLICATION),
    LIST_VIEW_GRID_LINES(false, APPLICATION),
    /**
     * Minimize after Autotype.
     */
    MINIMIZE_ON_AUTOTYPE(true, APPLICATION),
    /**
     * Show Username in Tree View.
     */
    SHOW_USERNAME_IN_TREE(true, DATABASE),
    /**
     * Generate pronounceable passwords.
     */
    PW_MAKE_PRONOUNCEABLE(false, DATABASE),
    /**
     * Clear clipboard upon minimize.
     * @deprecated typo in the name
     * @see #CLEAR_CLIPBOARD_ON_MINIMIZE
     */
    @Deprecated
    CLEAR_CLIPOARD_ON_MINIMIZE(true, OBSOLETE),
    /**
     * Clear clipboard upon exit.
     * @deprecated two typos in the name
     * @see #CLEAR_CLIPBOARD_ON_EXIT
     */
    @Deprecated
    CLEAR_CLIPBOARD_ONE_EXIT(true, OBSOLETE),
    SHOW_TOOLBAR(true, APPLICATION),
    /**
     * Show Notes as ToolTips in Tree &amp; List views.
     */
    SHOW_NOTES_AS_TOOLTIPS_IN_VIEWS(false, APPLICATION),
    /**
     * Open database as read-only by default.
     */
    DEFAULT_OPEN_RO(false, APPLICATION),
    /**
     * Allow multiple instances.
     */
    MULTIPLE_INSTANCES(true, APPLICATION),
    SHOW_DRAGBAR(true, APPLICATION),
    /**
     * Clear clipboard upon minimize.
     */
    CLEAR_CLIPBOARD_ON_MINIMIZE(true, APPLICATION),
    /**
     * Clear clipboard upon exit.
     */
    CLEAR_CLIPBOARD_ON_EXIT(true, APPLICATION),
    SHOW_FIND_TOOLBAR_ON_OPEN(false, APPLICATION),
    /**
     * Word Wrap Notes in Add &amp; Edit.
     */
    NOTES_WORD_WRAP(false, APPLICATION),
    /**
     * Lock password database after {@link IntegerPrefType#IDLE_TIMEOUT}
     * minutes idle.
     */
    LOCK_DB_ON_IDLE_TIMEOUT(true, DATABASE),
    HIGHLIGHT_CHANGES(true, APPLICATION);

    private final boolean defaultValue;
    private final PrefStorageType storageType;

    BooleanPrefType(boolean defaultValue, PrefStorageType storageType) {
        this.defaultValue = defaultValue;
        this.storageType = storageType;
    }

    public boolean getDefaultValue() {
        return defaultValue;
    }

    public PrefStorageType getStorageType() {
        return storageType;
    }

    public static BooleanPrefType forId(int id) {
        BooleanPrefType[] values = values();
        if (id < 0 || id >= values.length) {
            return null;
        }
        return values[id];
    }
}
